﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EnemySystem : MonoBehaviour
{
    public GameObject[] Waves;
    public int current_wave_num;
    public float wave_time;//波数间隔时间
    private float current_time;//当前时间
    private bool wave_next;
    public GameObject victory_window;
    public Text wave_text;
    void Start()
    {
        current_wave_num = 0;
        current_time = wave_time;
        wave_next = true;
    }
    void Update()
    {
        Check();
        Time_wave();
        wave_text.text = (current_wave_num + 1).ToString();
    }

    void Time_wave()
    {
        if (current_time > 0 && wave_next)
        {
            current_time -= Time.deltaTime;
        }
        else if (current_time <= 0 && wave_next)
        {
            Next_wave_come();
        }
    }
    void Next_wave_come()//下一波
    {
        Waves[current_wave_num].SetActive(true);
        wave_next = false;
        current_time = wave_time;
    }

    void Check()
    {
        if (Waves[current_wave_num].transform.childCount == 0 && !wave_next)
        {
            current_wave_num++;
            wave_next = true;

            if(current_wave_num == 9)
            {
                Time.timeScale = 0f;
                victory_window.SetActive(true);//胜利
            }
        }
    }
}
